//
//  DZZCollectionCell.m
//  DZZTravel
//
//  Created by xalo on 16/7/16.
//  Copyright © 2016年 Eason. All rights reserved.
//

#import "DZZCollectionCell.h"

@interface DZZCollectionCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@property (nonatomic,strong)NSMutableArray *muArray;

@end

@implementation DZZCollectionCell

- (NSMutableArray *)muArray{
    
    if (!_muArray) {
        _muArray = [NSMutableArray array];
    }
    return _muArray;
}

- (void)awakeFromNib {
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
  
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    //设置滑动方向
//    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
//    设置item的大小
    self.collectionView.backgroundColor = [UIColor whiteColor];
    layout.itemSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width-20)/3, ([UIScreen mainScreen].bounds.size.width-20)/3-20);
//    设置间距
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    layout.minimumInteritemSpacing = 5;
    self.collectionView.collectionViewLayout = layout;
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"DZZListCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"DZZListCollectionCell"];
  
    
}

#pragma mark -----------collectionDelegate-------
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.muArray.count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DZZListCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DZZListCollectionCell" forIndexPath:indexPath];
    DZZRecommedModel *recommed = self.muArray[indexPath.row];
    [cell.bigImv sd_setImageWithURL:[NSURL URLWithString:recommed.coverPic] placeholderImage:[UIImage imageNamed:@"bs"]];
    cell.nameLabel.text = recommed.name;
//    cell.backgroundColor =[UIColor purpleColor];
    
    
    
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%ld",(long)indexPath.row);
    
    
}


//传过来一个数组
- (void)setCellOfArray:(NSMutableArray *)array{
    
    self.muArray = array;
    [self.collectionView reloadData];
    
}

@end
